import {LGXEnums}  from "../../common/sysenum";


class RMenuSvc {
    constructor(dataManger) {
        this.dataManger = dataManger;
    }

    chkItemCanDis(item) {
        let flag = true;
        switch (item) {
            case "finish":
                flag = this.chkDrawingPolyline();
                break;

            case "close":
                flag = this.chkDrawingPolylineClose();
                break;

            case "delete":
                flag = this.chkCanDelete();
                break;

            case "makeAsTitle":
                flag = this.chkCanMakeAsTitle();
                break;

            case "makeAsTitleZone":
            case "makeAsEdge":
            case "symbolUnitHighSetting":
                flag = this.chkSelRect();
                break;

            case "makeAsLeadwire":
                flag = this.chkCanMakeAsLeadwire();
                break;

            case "switchState":
                flag = this.canSwitchState();
                break;

            case 'insertItem':
                flag = this.canInsertItem();
                break;
        }
        return flag;
    }

    chkSelRect() {
        let flag = false;
        let curentGraph = this.dataManger.getCurentGraph();
        if (curentGraph && (curentGraph.m_graphType == LGXEnums.LGXGraphType.RectGraph_type
            ||curentGraph.m_graphType == LGXEnums.LGXGraphType.PolygonGraph_type)) {
            flag = true;
        }
        return flag;
    }

    chkCanMakeAsTitle() {
        let flag = false;
        let curentGraph = this.dataManger.getCurentGraph();
        if (curentGraph && curentGraph.m_graphType == LGXEnums.LGXGraphType.TextGraph_type) {
            flag = true;
        }
        return flag;
    }

    chkCanMakeAsLeadwire(){
        let flag = false;
        let curentGraph = this.dataManger.getCurentGraph();
        if (curentGraph && curentGraph.m_graphType == LGXEnums.LGXGraphType.LineGraph_type) {
            flag = true;
        }
        return flag;
    }

    chkCanDelete() {
        let flag = true;
        let curentGraph = this.dataManger.getCurentGraph();
        if (!curentGraph) {
            flag = false;
        }
        return flag;
    }
    chkDrawingPolyline() {
        let curentGraph = this.dataManger.getCurentGraph();
        if (!curentGraph) {
            return false;
        }
        if (curentGraph.m_graphType != LGXEnums.LGXGraphType.LineGraph_type) {
            return false;
        }
        let flag = false;
        if (curentGraph.getStart() == 1 && curentGraph.getFinish() == 0) {
            flag = true;
        }
        return flag;
    }

    chkDrawingPolylineClose() {
        let curentGraph = this.dataManger.getCurentGraph();
        let flag = this.chkDrawingPolyline();
        if (flag) {
            let position = curentGraph.getPosCopy();
            let ptCount = position.posList.length;
            if (ptCount > 2) {
                flag = true;
            }
            else {
                flag = false;
            }
        }
        return flag;
    }

    canSwitchState(){
        let curentGraph = this.dataManger.getCurentGraph();
        if (!curentGraph) {
            return false;
        }
        let flag = false;
        let symbol = curentGraph.getSymbol();
        if (symbol) {
            let stateCount = this.dataManger.getSymbolManager().getSymbolStateCount(symbol.m_typeID);
            if (stateCount > 1){
                flag = true;
            }
        }
        
        return flag;
    }

    canInsertItem() {
        let flag = false;
        let curentGraph = this.dataManger.getCurentGraph();
        if (curentGraph && (curentGraph.m_graphType == LGXEnums.LGXGraphType.XMindTheme_type)) {
            flag = true;
        }
        return flag;
    }

}

export default { RMenuSvc }